package basis;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

/**
 * 用控制台打印任意长度的菱形
 * 
 * @author 71936_000
 * 
 */

public class Damo1_Diamond {

	/*public static void main(String[] args) {
		System.out.println("请输入你要打印的菱形的宽度");
		Scanner sc = new Scanner(System.in);
		printDiamond(sc.nextInt());
	}*/
	
	@Test
	public void testPrintDiamond() {
		System.out.println("请输入你要打印的菱形的宽度");
		Scanner sc = new Scanner(System.in);
		printDiamond(sc.nextInt());
	}

	@Test
	public void testRegex() {
		
		Pattern p=Pattern.compile("\\d{4}-(?:\\d{2})-(\\d{2})");
		Matcher m=p.matcher("2017-02-01");
		if(m.find()) {
			System.out.println(m.group(0));
			System.out.println(m.group(1));
		}
	}
	
	@Test
	public  void printTest( ){
		System.out.println("请输入你要打印的菱形的宽度");
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		for (int i = 1; i <= num; i++) { // 菱形的上半部分
			
			for (int x = num; x > i; x--) {
				System.out.print(" ");
			}
			for (int y = 0; y < i; y++) {
				System.out.print(" *");
			}
			System.out.println();
		}
		for (int i = 1; i < num; i++) { // 菱形的下半部分
			for (int x = 0; x < i; x++) {
				System.out.print(" ");
			}
			for (int y = num; y > i; y--) {
				System.out.print(" *");
			}
			System.out.println();
		}
	}
	
	public static void printDiamond(int num) {
		for (int i = 1; i <= num; i++) { // 菱形的上半部分
			for (int x = num; x > i; x--) {
				System.out.print(" ");
			}
			for (int y = 0; y < i; y++) {
				System.out.print(" *");
			}
			System.out.println();
		}
		for (int i = 1; i < num; i++) { // 菱形的下半部分
			for (int x = 0; x < i; x++) {
				System.out.print(" ");
			}
			for (int y = num; y > i; y--) {
				System.out.print(" *");
			}
			System.out.println();
		}
	}
}
